﻿@using Model.Util;
@using Xproject.Util;
@{
    string Domain = CommonHelper.GetAppSettings("Domin");
    Layout = "~/Views/Shared/_JSlayout.cshtml";
    string defaultUrl = Domain+"/Shop/CateProList";
}
@model IndexCategory
<div class="gray-bg">
    <div class="  animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>@ViewBag.Title</h5>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="formRole" action="~/Category/EditIndexCategory" method="post">

                            <div class="form-group">
                                <label class="col-sm-3 control-label">分类显示名：</label>
                                <div class="col-sm-8">
                                    <input id="IndexCateShowName" name="IndexCateShowName" required class="form-control" type="text"   min="4" value="@(Model!=null?Model.IndexCateShowName:"")">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">点击链接：</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="IndexCateUrl" id="IndexCateUrl" placeholder="" required value="@(Model!=null?Model.IndexCateUrl:defaultUrl)" />
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">排序值：</label>
                                <div class="col-sm-8">
                                    <input id="Sort" name="Sort" class="form-control" type="number" aria-required="true" aria-invalid="false" class="valid" value="@(Model!=null?Model.Sort:0)" required>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">选择分类：</label>
                                <div class="col-sm-8">
                                    <select data-val="true" data-val-number="字段 CategoryID 必须是一个数字。" required  data-val-range="请选择分类" data-val-required="CategoryID 字段是必需的。" id="CategoryID" name="CategoryID">
                                        @if (Model != null)
                                        {
                                            <option @if (0 == Model.CategoryID) { <text> selected="selected" </text> }
                                                    value="0">
                                                顶层分类
                                            </option>
                                            foreach (Category info in ViewData["categoryList"] as List<Category>)
                                            {
                                            <option @if (info.CategoryID == Model.CategoryID) { <text> selected="selected" </text> }
                                                    value="@info.CategoryID">
                                                @Html.Raw(CommonHelper.GetHtmlBS(info.Layer - 1)) @info.Name
                                            </option>
                                            }
                                        }
                                        else
                                        {
                                            <option  value="0">
                                                顶层分类
                                            </option>
                                            foreach (Category info in ViewData["categoryList"] as List<Category>)
                                            {
                                            <option  
                                                    value="@info.CategoryID">
                                                @Html.Raw(CommonHelper.GetHtmlBS(info.Layer - 1)) @info.Name
                                            </option>
                                            }
                                        }

                                    </select>
                                </div>
                            </div>
                         
                            <div class="form-group">
                                <label class="col-sm-3 control-label">备注：</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="Remarks" id="Remarks" placeholder="备注" required value="@(Model!=null?Model.Remarks:"")" />
                                </div>
                            </div>



                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <div class="checkbox">
                                        <label>
                                            @if (Model != null)
                    {
                        <input type="checkbox" @(Model.Enable == 1 ? "checked" : "") class="checkbox" id="Enable" name="Enable">@("启用")
}
else
{
                        <input type="checkbox" class="checkbox" id="Enable" name="Enable">@("启用")
}
                                        </label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">广告图</label>
                                <div class="col-sm-4">
                                    <input id="productContentImg" name="productContentImg" class="form-control" type="file">
                                    @if (Model != null)
            {
                        <img id="img" src="@(Model != null ? Model.IconImg : "")" style="width:200px;height:160px;">
}
else
{
                        <img id="img" src="" style="width:200px;height:160px;display:none">
}
                                    <input id="hiddenIndex" value="" type="hidden" />
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    @if (Model != null)
            {
                        <input type="hidden" name="IndexCateId" value="@Model.IndexCateId" />
}
                                    <button class="btn btn-primary" type="submit">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 全局js -->

<script type="text/javascript">
    $(document).ready(function () {
        var optionsNew = {
            beforeSubmit: function () {
                //layer.open({ type: 2, time: 2 });
                layer.load(1, { shade: [0.1, '#000'], time: 2000 });
            },
            success: function (data) {
                if (data.Success == true) {
                    layer.alert('编辑成功', { icon: 1, skin: 'layer-ext-moon', time: 2000 });
                } else {
                    layer.alert(data.Data, { icon: 1, skin: 'layer-ext-moon', time: 2000 });
                }
            },
            error: function () {
                alert(JSON.stringify(data));
            },
            type: "post",
            clearForm: false,
            timeout: 100000
        };

        $("#formRole").submit(function () {
            $("#formRole").ajaxSubmit(optionsNew);// type="button"
            return false;
        });
    });

    $("#productContentImg").on("change", function () {
        var file = this.files[0];
        if (this.files && file) {
            var reader = new FileReader();
            reader.onload = function (e) {
                $("#img").attr("src", e.target.result);
                $("#img").show();
            }
            reader.readAsDataURL(file);
        }
    });
</script>


